@extends('layouts.main')



@section('content')

    {{--  查询订单  --}}

    <form action="" method="get">
        <div class="text-center">
            <input type="text" style="height:30px;margin-top:10px;" class="span3" name="order_id"
                   placeholder="请输入您查询的订单号"> <input type="submit" class="span1 btn btn-info" value="查询" name="ssbtn" />
        </div>

    </form>

    <br><br>
    <table class="table table-striped  text-center table-bordered table-hover table-condensed">
        <thead>
        <tr>
            <th class="info">订单号</th>
            <th class="info">下单时间</th>
            <th class="info">总价</th>
            <th class="info">状态</th>
            <th class="info">操作</th>
        </tr>
        </thead>

        @foreach($orders as $order)

            <tr height="40px">
                <td style="width:150px;">{{$order->order_id ?? ''}}</td>
                <td style="width:150px;">{{$order->time ?? ''}}</td>
                <td style="width:150px;">{{$order->totalprice ?? ''}}元</td>
                <td style="width:150px;">{{$order->order_state_cn ?? ''}}</td>
                <td style="width:150px;">

                    @if($order->order_state == 1)
                        <button class="pay-btn btn" data-order_id="{{$order->order_id}}">支付订单</button>
                    @endif
                    @if($order->order_state == 3)
                        <button class="complate-btn btn" data-order_id="{{$order->order_id}}">确认收货</button>
                    @endif
                    <button class="btn">
                        <a href="{{route('order.show',['order_id'=>$order->order_id])}}" target="_blank">查看详情</a>
                    </button>
                </td>

            </tr>
        @endforeach
    </table>
    <div class="text-center">
        {{ $orders->links() }}</div>
@endsection

@section('scripts')
    <script>
        $('.pay-btn').click(function () {
            let order_id = $(this).data('order_id');

            location.href = '{{route('order.pay_view')}}?order_id=' + order_id;
            return ;
            $.post('{{route('order.pay')}}', {
                order_id: order_id
            }, function (res) {
                location.reload();
            })
        });

        $('.complate-btn').click(function () {
            let order_id = $(this).data('order_id');
            $.post('{{route('order.complete')}}', {
                order_id: order_id
            }, function (res) {
                location.reload();
            })
        });

    </script>
@endsection
